package cn.springcloud.fix.demo.proxy.jdk;

import cn.springcloud.fix.demo.proxy.Person;
import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;

public class XiaoMing implements Person {

    @Override
    public void findLove() {
        System.out.println("好的，我想找个漂亮老婆");
    }

    public static void main(String[] args) {
        XiaoMing xiaoMing = new XiaoMing();
        Person proxy = (Person) new MeiPo().getProxy(xiaoMing);
        System.out.println("代理对象的class：" + proxy.getClass());
        proxy.findLove();

        try {
            byte[] data = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{Person.class});
            FileOutputStream os = new FileOutputStream("/Users/yangjun/Desktop/logs/$Proxy0.class");
            os.write(data);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
